package edu.sdufe.copy;

/**
 * @author wang'ji'cheng
 * @date 2025/6/29
 */
public class ShallowCopyDemo {
    public static void main(String[] args) {
        String[] hobby1 = {"吃饭","睡觉"};
        String[] hobby2 = {"吃饭","睡觉"};
        Student student1 = new Student("张三",20 ,hobby1);
        Student student2 = new Student("李四",21,hobby2);
        System.out.println("初始化的学生对象1"+student1);
        Student clone1 = student1.clone();
        Student clone2 = student2.deepClone();
        String[] hobby = clone1.getHobby();
        hobby[0]="打游戏";
        String[] hobby3 =student2.getHobby();
        hobby3[0]="修改后的爱好";


        System.out.println("深克隆出的学生对象"+clone2);
        System.out.println("原始的学生对象2(被修改过)"+student2);


       System.out.println("浅克隆出的学生对象"+clone1);

        System.out.println("原始的学生对象1"+student1);


    }
}
